package com.coscon.service.patternCommon;

import com.coscon.enums.VideoCmdEnum;
import com.coscon.model.IrcaCmd;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.SystemUtils;

import javax.websocket.Session;
import java.util.HashMap;
import java.util.Map;

/**
 * 视频播放器的控制器
 * @author 409390047@qq.com
 */
@Slf4j
public class VideoRemoteControl {
    //所有命令的集合
    private Map<String,ICommand> execCommands;

    // 初始化遥控器按钮功能
    public VideoRemoteControl(){
        execCommands = new HashMap<>();
    }
    //设置一个
    public void addCommand(VideoCmdEnum cmdEnum, ICommand onCommand){
        execCommands.put(cmdEnum.getKey(),onCommand);
    }


    //执行某个命令
    public Boolean execCmd(IrcaCmd ircaCmd, Session session){
        ICommand iCommand = execCommands.get(ircaCmd.getCmd());
        if(iCommand==null){
            return false;
        }
        if(SystemUtils.IS_OS_MAC){
            return iCommand.executeByMac(ircaCmd,session);
        }else if(SystemUtils.IS_OS_WINDOWS){
            return iCommand.executeByWin(ircaCmd,session);
        }else if(SystemUtils.IS_OS_LINUX){
            return iCommand.executeByLinux(ircaCmd,session);
        }else{
            log.debug("不支持的操作系统");
        }
        return  false;
    }


}
